/*
 * Based on 
 * JBox2D - A Java Port of Erin Catto's Box2D
 * 
 * JBox2D homepage: http://jbox2d.sourceforge.net/ 
 * Box2D homepage: http://www.box2d.org
 * 
 */

package pl.put.miasi.volleyball;


import java.util.Random;

import org.jbox2d.common.Vec2;

public class Settings {
    public int hz;

    public int iterationCount;

    public boolean enableWarmStarting;
    public boolean enablePositionCorrection;
    public boolean enableTOI;

	public boolean pause;
	public boolean singleStep;

	public boolean drawShapes;
	public boolean drawJoints;
	public boolean drawCoreShapes;
	public boolean drawOBBs;
	public boolean drawCOMs;
    public boolean drawStats;
    public boolean drawImpulses;
    public boolean drawAABBs;
    public boolean drawPairs;
	public boolean drawContactPoints;
	public boolean drawContactNormals;
	public boolean drawContactForces;
	public boolean drawFrictionForces;
	
	public static Random random = new Random(System.currentTimeMillis());
	
	/*
	 * BEG: Our Code
	 */
	static final float GRAVITY_X = 0.0f;
	static final float GRAVITY_Y = -3.0f;	

	//camera scale;
	static final float CS = 80.0f;

	static final float WORLD_WIDTH_PX = 1500.0f;
	static final float WORLD_HEIGHT_PX = 800.0f;
	static final float FOOTNOTE_PX = 110.0f;
	static final float BORDER_PX = 30.0f;

	//Camera placed at the very center of court
	static final float CAMERA_X = 0.0f;
	static final float CAMERA_Y = WORLD_HEIGHT_PX / 2.0f / CS - FOOTNOTE_PX / CS;
	
	static final float WORLD_MIN_X = -WORLD_WIDTH_PX/2.0f/CS;
	static final float WORLD_MIN_Y = 0.0f/CS;
	static final float WORLD_MAX_X = WORLD_WIDTH_PX/2.0f/CS;
	static final float WORLD_MAX_Y = WORLD_HEIGHT_PX/CS;
	
	static final Vec2 WHOLE_WORLD_LB = new Vec2(WORLD_MIN_X, WORLD_MIN_Y);
	static final Vec2 WHOLE_WORLD_UB = new Vec2(WORLD_MAX_X, WORLD_MAX_Y);
	
	//World border
	static final float BORDER = BORDER_PX / CS;
	static final float FOOTNOTE = FOOTNOTE_PX / CS;
	
	//Actual world constraints
	static final float ACT_WORLD_MIN_X = WORLD_MIN_X + BORDER;
	static final float ACT_WORLD_MIN_Y = WORLD_MIN_Y + BORDER;
	static final float ACT_WORLD_MAX_X = WORLD_MAX_X - BORDER;
	static final float ACT_WORLD_MAX_Y = WORLD_MAX_Y - BORDER - FOOTNOTE;
	static final float ACT_WORLD_HX = (ACT_WORLD_MAX_X - ACT_WORLD_MIN_X) / 2.0f;
	static final float ACT_WORLD_HY = (ACT_WORLD_MAX_Y - ACT_WORLD_MIN_Y) / 2.0f;
	static final float ACT_WORLD_CENTER_X = (ACT_WORLD_MAX_X + ACT_WORLD_MIN_X) / 2.0f;
	static final float ACT_WORLD_CENTER_Y = (ACT_WORLD_MAX_Y + ACT_WORLD_MIN_Y) / 2.0f;
	
	//Initial position of ball
	static final Vec2 INITIAL_BALL_POS = new Vec2(ACT_WORLD_CENTER_X, (ACT_WORLD_MAX_Y + ACT_WORLD_MIN_Y) * 7.0f / 8.0f);
	static final Vec2 INITIAL_BALL_LINEAR_VEL() {
		return new Vec2(random.nextFloat()*10.0f - 5.0f, 0);
	}
	
	static float INITIAL_BALL_ANGULAR_VEL() {
		return random.nextFloat()*10.0f - 5.0f;
	}

	//Borders position and constraints
	//Floor
	static final float groundHX = (WORLD_MAX_X - WORLD_MIN_X) / 2.0f;
	static final float groundHY = (BORDER) / 2.0f;
	static final Vec2 groundPos = new Vec2(0.0f, BORDER / 2.0f);
	
	//Left wall
	static final float lWallHX = (BORDER) / 2.0f;
	static final float lWallHY = (WORLD_MAX_Y - WORLD_MIN_Y - FOOTNOTE) / 2.0f;
	static final Vec2 lWallPos = new Vec2(WORLD_MIN_X + BORDER / 2.0f, (WORLD_MIN_Y + WORLD_MAX_Y - FOOTNOTE) / 2.0f);
	//Right wall
	static final float rWallHX = (BORDER) / 2.0f;
	static final float rWallHY = (WORLD_MAX_Y - WORLD_MIN_Y - FOOTNOTE) / 2.0f;
	static final Vec2 rWallPos = new Vec2(WORLD_MAX_X - BORDER / 2.0f, (WORLD_MIN_Y + WORLD_MAX_Y - FOOTNOTE) / 2.0f);
	
	//Ceiling
	static final float ceilingHX = (WORLD_MAX_X - WORLD_MIN_X) / 2.0f;
	static final float ceilingHY = (BORDER) / 2.0f;
	static final Vec2 ceilingPos = new Vec2(0.0f, WORLD_MAX_Y - BORDER / 2.0f - FOOTNOTE);
	
	//Lower net
	static final float lowerNetHX = BORDER / 2.0f;
	static final float lowerNetHY = ACT_WORLD_HY * 5.0f / 21.0f;
	static final Vec2 lowerNetPos = new Vec2(0.0f, ACT_WORLD_MIN_Y + lowerNetHY);
	
	static final float WALL_RESTITUTION = 0.0f;
	static final float WALL_FRICTION = 1.0f;

	
	public static final float PLAYER_WHEEL = 30.0f / CS;
	public static final float PLAYER_WHEEL_X = 0.0f / CS;
	public static final float PLAYER_WHEEL_Y = 40.0f / CS;
	//we can do it by rectangle simply
	public static final float PLAYER_CORPS_DX = 70.0f / CS / 2;
	public static final float PLAYER_CORPS_DY = 185.0f / CS / 2;
	public static final float PLAYER_CORPS_X = 0.0f / CS;
	public static final float PLAYER_CORPS_Y = 127.5f / CS;
	
	public static final float PLAYER_WHEEL_ANCHOR_X = 0.0f / CS;
	public static final float PLAYER_WHEEL_ANCHOR_Y = 40.0f / CS;
	
	public static final float PLAYER_RACKET_DX = 65.0f / CS / 2;
	public static final float PLAYER_RACKET_DY = 20.0f / CS / 2;
	public static final float PLAYER_RACKET_X = 0.0f / CS;
	public static final float PLAYER_RACKET_Y = 210.0f / CS;
	
	public static final float PLAYER_RACKET_ANCHOR_X = 0.0f / CS;
	public static final float PLAYER_RACKET_ANCHOR_Y = 210.0f / CS;

	public static final Vec2 INITIAL_PLAYER_POS = new Vec2(-5.0f, 0.8f);
	
	//players initial positions
	
	public static final float PLAYER_POSITION_DX = (ACT_WORLD_MAX_X - ACT_WORLD_MIN_X) / 10.0f;
	public static final float PLAYER_INITIAL_Y = 50.f / CS;
	public static final Vec2[] PLAYERS_INITIAL = new Vec2[] {
		new Vec2((ACT_WORLD_MIN_X + PLAYER_POSITION_DX * 1), PLAYER_INITIAL_Y),
		new Vec2((ACT_WORLD_MIN_X + PLAYER_POSITION_DX * 2), PLAYER_INITIAL_Y),
		new Vec2((ACT_WORLD_MIN_X + PLAYER_POSITION_DX * 3), PLAYER_INITIAL_Y),
		new Vec2((ACT_WORLD_MIN_X + PLAYER_POSITION_DX * 7), PLAYER_INITIAL_Y),
		new Vec2((ACT_WORLD_MIN_X + PLAYER_POSITION_DX * 8), PLAYER_INITIAL_Y),
		new Vec2((ACT_WORLD_MIN_X + PLAYER_POSITION_DX * 9), PLAYER_INITIAL_Y)
	};
	
	
	public static final float PLAYER_MOVE = 0.5f;
	public static final float PLAYER_ROTATION = 0.2f;
	public static final float PLAYER_RESTITUTION = 0.1f;
	public static final float PLAYER_DENSITY = 10.0f;
	public static final float PLAYER_FRICTION = 0.1f;
	public static final float PLAYER_RACKET_RESTITUTION = 0.5f;
	
	
	
	public static final float BALL_RADIUS_PX = 30.0f;
	public static final float BALL_DENSITY = 0.1f;
	public static final float BALL_FRICTION = 0.1f;
	public static final float BALL_RESTITUTION = 0.8f;
	public static final float BALL_RADIUS = BALL_RADIUS_PX / CS;
	

    public static final String WALKING_WAV = "dzwieki\\walking.wav"; 
    public static final String RETURNING_WAV = "dzwieki\\returning.wav"; 
    public static final String NEWROUND_WAV = "dzwieki\\newround.wav"; 

    public static final int COLLISION_BIT_DEFAULT = 0x0001;
    public static final int COLLISION_BIT_TERRAIN = 0x0002;
    public static final int COLLISION_BIT_PLAYER = 0x0004;
    public static final int COLLISION_BIT_BALL = 0x0008;
    
    public static final int RESULT_X = 650;
    public static final int RESULT_Y = 740;
    public static final int END_X = 600;
    public static final int END_Y = 770;
    public static final int RESET_X = 600;
    public static final int RESET_Y = 770;
    
    public static final int PLAY_UNTIL = 11;
    
    public static final int LOADING = 10000;
    
    /********/

    public Settings() {
        hz = 20;
        iterationCount = 10;
        drawStats = true;
        drawAABBs = false;
        drawPairs = false;
        drawShapes = false;
        drawJoints = false;
        drawCoreShapes = false;
        drawContactPoints = false;
        drawContactNormals = false;
        drawContactForces = false;
        drawFrictionForces = false;
        drawOBBs = false;
        drawCOMs = false;
        enableWarmStarting = true;
        enablePositionCorrection = true;
        enableTOI = true;
        pause = false;
        singleStep = false;
    }
}
